clear all;

cd ..; cd ..; cd ..;
load('code_main_model\6_implied_w_r\computation_results\data.mat','nmkt','period_trans','pdf_B_forward',...
    'GDP','frac_entre','labor_demand_stat','frac_credit');
cd 'code_figure_table\maintext\Figure 8';

size=sum(pdf_B_forward,[3,4,5]);
frac_credit_normalized=frac_credit./size(1:period_trans-1,:);

year=1:11;
nyear=length(year);
agg_GDP(1:nyear,1)=nan;
agg_entre(1:nyear,1)=nan;
agg_farmer(1:nyear,1)=nan;
agg_worker(1:nyear,1)=nan;
agg_credit(1:nyear,1)=nan;
agg_credit_gini(1:nyear,1)=nan;

pop=1e10;

for i_t=1:nyear
    agg_GDP(i_t)=sum(GDP(i_t,:));
    agg_entre(i_t)=sum(frac_entre(i_t,:));
    agg_worker(i_t)=sum(labor_demand_stat(i_t,:));
    agg_farmer(i_t)=1-agg_entre(i_t)-agg_worker(i_t);
    agg_credit(i_t)=sum(frac_credit(i_t,:))/agg_entre(i_t);
    agg_credit_gini(i_t)=gini(ones(nmkt,1),frac_credit_normalized(i_t,:),false);
end

agg_GDP=agg_GDP./agg_GDP(1);



save('baseline.mat');
% save('credit.mat');
% save('deposit.mat');
